package com.zzty.serviceimpl;

import com.zzty.dao.UserDao;
import com.zzty.daoimpl.UserDaoImpl;
import com.zzty.entity.User;
import com.zzty.service.BoolUserService;

public class BoolUserServiceImpl implements BoolUserService {
    public String boolUser(User user)throws Exception{
       String result="success";
       UserDao ud=new UserDaoImpl();
       User us=ud.searchUserByName(user.getName());
       if(user.getName().equals(us.getName())){
           result="exist";
                   }
        if("success".equals(result)){
           ud.addUser(user);
               }
        return result;
    }
    public String boolUserSecret(User user)throws Exception{
        String result="false";
        UserDao ud=new UserDaoImpl();
        User u=ud.searchUserById(user.getId());
            if(user.getName().equals(u.getName())&&user.getPassword().equals(u.getPassword())){
                result=u.getType();
            }
        return result;
    }
    public Integer searchId(User user)throws Exception{
        Integer result=null;
        UserDao ud=new UserDaoImpl();
        User u=ud.searchUserByName(user.getName());
        System.out.println("uname="+u.getName()+"username="+user.getName());
            if(user.getName().equals(u.getName())){
                result=u.getId();
            }
          return result;
    }
    public User searchUser(Integer id)throws Exception{
        UserDaoImpl ud=new UserDaoImpl();
        User user=ud.searchUserById(id);
        return user;
    }
    public String changePassword(User user)throws Exception{
        String result="success";
        UserDaoImpl ud=new UserDaoImpl();
        User us=ud.searchUserByName(user.getName());
        if(user.getName().equals(us.getName())){
            result="exist";
        }
        if("success".equals(result)){
            result=ud.changeUser(user);
        }
        return result;
    }
}
